function isNumberKey(evt)
  {
	 var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	 return true;
  }
function subProductsDetails(id)
{
	var vehicleId = $("#hidUserID").val();
	$("#subProducts").html("<img src='images/loading.gif' height='20px;'>");

	if(id=="Select Products")
	{
	var data = "<select id='strProducts' name='strProducts' ><option>Select Products first</option></select>";
	$("#subProducts").html(data);
	}
	else
	{		
		$.post("ajax/subproducts.php",{productId:id,vehicleId:vehicleId,action:'subproducts'},function(data)
		{
			$("#subProducts").html(data);
		},"text");
	}
}

function saveProducts(url)
{
	var vehicleStatus = $("input[@name='VehicleStatus']:checked").val();
	var strProducts = $.trim($("#strProducts").val());
	var strsubProducts = $.trim($("#strsubProducts").val());
	var txtYear = $.trim($("#txtYear").val());
	var txtSeries = $.trim($("#txtSeries").val());
	var txtTitle = $.trim($("#txtTitle").val());
	var txtoriginalprice = $.trim($("#txtoriginalprice").val());
	var txtofferedprice = $.trim($("#txtofferedprice").val());
	var vehicleId = $("#hidUserID").val();
	var errMsg="";

	if(strProducts=="")
	{
		errMsg = "Please select a product from product list.\n";
	}
	if(strsubProducts=="")
	{
		errMsg += "Please select a sub product from sub product list.\n";
	}
	if(txtYear.length==0)
	{
		errMsg += "Please enter a year.\n";
	}
	if(txtSeries.length==0)
	{
		errMsg += "Please enter a series.\n";
	}
	if(txtTitle.length==0)
	{
		errMsg += "Please enter a title.\n";
	}
	if(txtoriginalprice.length=="")
	{
		errMsg += "Please enter original price.\n";
	}
	if(txtofferedprice.length=="")
	{
		errMsg += "Please enter offered price.\n";
	}
	if(vehicleStatus.length==1)
	{
		errMsg += "Please select a Vehicle Status.\n";
	}
	if(chkProducts()==false)
	{
		errMsg += "This series already exists.Please enter another name.\n";
	}	
	if(errMsg !="")
	{
	alert(errMsg);
	$("#loading").hide();
	}
	else
	{
	$("#loading").show();
	
	$.ajax({
	type: "POST",
	url: "savealldata.php",
	data: "productId="+strProducts+"&subProductId="+strsubProducts+"&txtYear="+txtYear+"&txtSeries="+txtSeries+"&txtTitle="+txtTitle+"&txtoriginalprice="+txtoriginalprice+"&txtofferedprice="+txtofferedprice+"&vehicleStatus="+vehicleStatus+"&action=saveproducts&vehicleId="+vehicleId,
	success: function(data){		
	      $("#hidUserID").val(data);
		 $('#tabs').tabs("select", 1);
	      window.location =  "imageupload.php?id="+$("#hidUserID").val();
		 $("#loading").hide();
	} });
	}
}

function chkProducts()
{
	var strProducts = $("#strProducts").val();
	var strsubProducts = $("#strsubProducts").val();
	var txtYear = $("#txtYear").val();
	var txtSeries = $("#txtSeries").val();
	var txtTitle = $("#txtTitle").val();
	var hidUserID = $("#hidUserID").val();	
	var valid=true;
	$.post("ajax/subproducts.php",{productId:strProducts,subProductId:strsubProducts,txtYear:txtYear,txtSeries:txtSeries,txtTitle:txtTitle,vehicleId:hidUserID,action:'chkproducts'},function(data)
	{
	if(data == 1)
		valid=false;
		else
		valid=true;
		
	},"text");
	return valid;
}

function saveOverview(url)
{
	var hidUserID = $("#hidUserID").val();	
	var textarea=tinyMCE.activeEditor.getContent({format : 'raw'});
	 $("#loading").show();
	$.ajax({
	type: "POST",
	url: "savealldata.php",
	data: "vehicleId="+ hidUserID+"&desc="+ textarea+"&action=saveoverview",
	success: function(data){
	       $('#tabs').tabs("select", 3);
	       window.location =  "specifications.php?id="+$("#hidUserID").val();		
		    $("#loading").hide();
	} });		
}

function saveSpecifications(url)
{
	var hidUserID = $("#hidUserID").val();	
	var txtEngineType = $("#txtEngineType").val();	
	var txtDisplacement = $("#txtDisplacement").val();
	var txtBoreStroke = $("#txtBoreStroke").val();
	var txtCylinders = $("#txtCylinders").val();
	var txtEngineCooling = $("#txtEngineCooling").val();
	var txtFuelSystem = $("#txtFuelSystem").val();	
	var txtStartingSystem = $("#txtStartingSystem").val();
	
	var txtFrontSuspension = $("#txtFrontSuspension").val();
	var txtFrontTravel = $("#txtFrontTravel").val();
	var txtFrontBrakeType = $("#txtFrontBrakeType").val();
	var txtFrontTires = $("#txtFrontTires").val();	
	var txtRearSuspension = $("#txtRearSuspension").val();
	var txtRearTravel = $("#txtRearTravel").val();
	var txtRearBrakeType = $("#txtRearBrakeType").val();
	var txtRearTires = $("#txtRearTires").val();
	var txtFrame = $("#txtFrame").val();	
	
	var txtDryWeight = $("#txtDryWeight").val();
	var txtFrontRackCapacity = $("#txtFrontRackCapacity").val();
	var txtRearRackCapacity = $("#txtRearRackCapacity").val();
	var txtTowingCapacity = $("#txtTowingCapacity").val();
	var txtFuelCapacity = $("#txtFuelCapacity").val();	
	
	var txtGroundClearance = $("#txtGroundClearance").val();
	var txtMachineDimensions = $("#txtMachineDimensions").val();
	var txtWheelbase = $("#txtWheelbase").val();
	
	var txtDriveTrain = $("#txtDriveTrain").val();
	var txtFinalDrive = $("#txtFinalDrive").val();	
	var txtTransmission = $("#txtTransmission").val();
	
	var txtSpeedometer = $("#txtSpeedometer").val();
	var txtTachometer = $("#txtTachometer").val();
	var txtOdometer = $("#txtOdometer").val();
	var txtLighting = $("#txtLighting").val();
	var txtColors = $("#txtColors").val();
	var txtWarranty = $("#txtWarranty").val();
	
	var str =  "vehicleId="+ hidUserID+"&txtEngineType="+txtEngineType+"&txtDisplacement="+txtDisplacement+"&txtBoreStroke="+txtBoreStroke
			   +"&txtCylinders="+txtCylinders+"&txtEngineCooling="+txtEngineCooling+"&txtFuelSystem="+txtFuelSystem+"&txtStartingSystem="
			   +txtStartingSystem+"&txtFrontSuspension="+txtFrontSuspension+"&txtFrontTravel="+txtFrontTravel+"&txtFrontBrakeType="
			   +txtFrontBrakeType+"&txtFrontTires="+txtFrontTires+"&txtRearSuspension="+txtRearSuspension+"&txtRearTravel="+txtRearTravel
			   +"&txtRearBrakeType="+txtRearBrakeType+"&txtRearTires="+txtRearTires+"&txtFrame="+txtFrame+"&txtDryWeight="+txtDryWeight
			   +"&txtFrontRackCapacity="+txtFrontRackCapacity+"&txtRearRackCapacity="+txtRearRackCapacity+"&txtTowingCapacity="+txtTowingCapacity
			   +"&txtGroundClearance="+txtGroundClearance+"&txtMachineDimensions="+txtMachineDimensions+"&txtWheelbase="+txtWheelbase
			   +"&txtDriveTrain="+txtDriveTrain+"&txtFinalDrive="+txtFinalDrive+"&txtTransmission="+txtTransmission+"&txtSpeedometer="
			   +txtSpeedometer+"&txtTachometer="+txtTachometer+"&txtOdometer="+txtOdometer+"&txtLighting="+txtLighting+"&txtColors="
			   +txtColors+"&txtWarranty="+txtWarranty+"&txtFuelCapacity="+txtFuelCapacity+"&action=savespecifications";
	$("#loading").show();
	$.ajax({
	type: "POST",
	url: "savealldata.php",
	data:  str,
	success: function(data){
	       alert("Data Saved Successfully.");
	       window.location = "home.php?mode=manage-vehicle";
		   $("#loading").hide();
	} });		
}

function clickme(pagename)
{
var hidUserID = $("#hidUserID").val();
if(hidUserID !="")
window.location = pagename+"?id="+hidUserID;
}

function deleteMe(id,vehicleid)
{
	$.ajax({
		type: "POST",
		url: "ajax/subproducts.php",
		data:  "action=deleteimages&id="+vehicleid+"&imgid="+id,
		success: function(data){
			$("#showImages").html(data);
		} });	
}